import * as fs from "fs";
import * as path from "path";
const isProd = process.env.NODE_ENV === "production";

function parseEnv() {
	const localEnv = path.resolve(".env.ts");
	const prodEnv = path.resolve(".env.prod.ts");

	if (!fs.existsSync(localEnv) && !fs.existsSync(prodEnv)) {
		throw new Error("缺少环境配置文件");
	}
	console.log("运行环境为：" + (isProd ? "生产环境" : "开发环境"));

	const filePath = isProd && fs.existsSync(prodEnv) ? prodEnv : localEnv;
	return { path: filePath };
}
export default parseEnv();
